import global from "./global";
import user from './users'
console.log(!global.host.includes("test"))
var SUGOIO_LIB_URL = global.host.includes("test")
  ? "//uits-test.infinitus.com.cn/uits-gateway/_bc/sugo-sdk-js/libs/sugoio-latest.min.js" //正式环境
  : "//uits.infinitus.com.cn/uits-gateway/_bc/sugo-sdk-js/libs/sugoio-latest.min.js"; //测试环境
//SUGOIO_LIB_URL = "//uits.infinitus.com.cn/uits-gateway/_bc/sugo-sdk-js/libs/sugoio-latest.min.js";

!(function (e, o) {
  function t(e, o) {
    for (var t = 0, n = e.length; t < n; t++) o(e[t], t, e);
  }
  if (!o.__SV) {
    var n,
      r,
      s,
      c = window,
      i = "sugoio";
    c[i] = o;
    try {
      !(function (o) {
        var t = c.atob(o),
          n = JSON.parse(t).state,
          r = {
            accessToken: n.access_token,
            accessTokenExpiresAt: Date.now() + 1e3 * Number(n.expires_in),
            projectToken: n.token,
            projectId: n.project_id,
            userId: n.user_id,
            choosePage: n.choose_page,
            viewType: n.viewType,
            heatmapType: n.heatmapType,
          };
        c.sessionStorage.setItem("editorParams", JSON.stringify(r)),
          n.hash
            ? (c.location.hash = n.hash)
            : c.history
            ? c.history.replaceState(
                "",
                e.title,
                c.location.pathname + c.location.search
              )
            : (c.location.hash = "");
      })(c.location.hash.replace("#", ""));
    } catch (a) {
    } finally {
      !(function (o) {
        var n = {},
          r = e,
          s =
            "blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(
              " "
            );
        (o.proxy = {
          proxy: function (e, t) {
            return (n[e] || (n[e] = [])).push(t), o.proxy;
          },
          off: function (e, r) {
            var s = n[e] || [],
              c = [];
            return (
              t(s, function (e) {
                e !== r && c.push(e);
              }),
              (s[e] = c),
              o.proxy
            );
          },
        }),
          t(s, function (e) {
            (n[e] = []),
              (function (e, o, t) {
                "function" == typeof e.addEventListener
                  ? e.addEventListener(o, t, !0)
                  : e.attachEvent("on" + o, t);
              })(r, e, function (o) {
                try {
                  t(n[e], function (e) {
                    e(o);
                  });
                } catch (a) {
                  console &&
                    "function" == typeof console.error &&
                    console.error(a.stack);
                }
              });
          });
      })(o);
    }
    (o._i = []),
      (o.init = function (e, n, r) {
        var c = o;
        void 0 !== r ? (c = o[r] = []) : (r = i),
          (c.people = c.people || []),
          (c.toString = function (e) {
            var o = i;
            return r !== i && (o += "." + r), e || (o += " (stub)"), o;
          }),
          (c.people.toString = function () {
            return c.toString(1) + ".people (stub)";
          }),
          t(
            (s =
              "time_event track track_pageview register register_once unregister set_config".split(
                " "
              )),
            function (e) {
              !(function (e, o) {
                var t = o.split(".");
                2 === t.length && ((e = e[t[0]]), (o = t[1])),
                  (e[o] = function () {
                    e.push(
                      [o].concat(Array.prototype.slice.call(arguments, 0))
                    );
                  });
              })(c, e);
            }
          ),
          o._i.push([e, n, r]);
      }),
      (o.__SV = 1.2),
      ((n = e.createElement("script")).type = "text/javascript"),
      (n.async = !0),
      "undefined" != typeof SUGOIO_CUSTOM_LIB_URL
        ? (n.src = SUGOIO_CUSTOM_LIB_URL)
        : "file:" === c.location.protocol && SUGOIO_LIB_URL.match(/^\/\//)
        ? (n.src = "https:" + SUGOIO_LIB_URL)
        : (n.src = SUGOIO_LIB_URL),
      (r = e.getElementsByTagName("script")[0]).parentNode.insertBefore(n, r);
  }
})(document, window.sugoio || []);
var _projectid = global.projectId; //项目id
var _token = global.sugoioToken; //项目token
var _app_name = global.appName; //应用名称
var _app_version = "1.0.0"; //应用版本
var _user_id = user.ID; //用户卡号
var _openid = ''; //openid
var _unionid = ""; //unionid
var _appid = global.appId; //appid
// setTimeout(() => {
  window.sugoio.init(_token, {
    project_id: _projectid,
    enable_hash: true, //识别带#页面
    loaded: function (lib) {
      window.sugoio.register({
        //设置全局变量
        app_name: _app_name,
        app_version: _app_version,
        UserID: _user_id,
        openid: _openid,
        unionid: _unionid,
        appid: _appid,
      });
    },
  });
// }, 100);
console.log('------')
console.log(window.sugoio)
console.log('------')